package m.jclecai.com.activity;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.squareup.okhttp.Request;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import m.jclecai.com.R;
import m.jclecai.com.adapter.PayRedpacketAdapter;
import m.jclecai.com.animal.ExpandAnimation;
import m.jclecai.com.base.BaseActivity;
import m.jclecai.com.bean.PlayItem;
import m.jclecai.com.bean.RedPacketBean;
import m.jclecai.com.bean.UserBean;
import m.jclecai.com.constant.Constant_Result;
import m.jclecai.com.constant.Constant_Url;
import m.jclecai.com.data.Lecai_SDK;
import m.jclecai.com.listener.Callback;
import m.jclecai.com.listener.NotifyTextViewSetChanged;
import m.jclecai.com.utils.BaseUtils;
import m.jclecai.com.utils.ChannelUtil;
import m.jclecai.com.utils.DateUtil;
import m.jclecai.com.utils.MyLog;
import m.jclecai.com.utils.MyToast;
import m.jclecai.com.utils.PreferenceUtil;
import m.jclecai.com.utils.http.FastOk;
import m.jclecai.com.utils.http.HttpManager;
import m.jclecai.com.utils.http.responseBody.DltBody;
import m.jclecai.com.utils.http.responseBody.RedpacketBody;

public class LotteryPayActivity extends BaseActivity implements NotifyTextViewSetChanged {


    public static final String  IS_CAN_USE_RED_PACKET="showRedPacket";

    @BindView(R.id.tv_rmb)
    TextView tv_rmb;
    @BindView(R.id.tv_bs)
    TextView tv_bs;
    @BindView(R.id.tv_play)
    TextView tv_play;
    @BindView(R.id.tv_all_pay)
    TextView tv_all_pay;
    @BindView(R.id.tv_hb_money)
    TextView tv_hb_money;
    @BindView(R.id.llhb)
    LinearLayout llhb;
    @BindView(R.id.iv_hb_icon)
    ImageView iv_hb_icon;
    @BindView(R.id.rv_pkg)
    RecyclerView rv_pkg;
    @BindView(R.id.tv_no)
    TextView tv_no;
    @BindView(R.id.tv_balance)
    TextView tvBalance;
    @BindView(R.id.tv_sure)
    TextView tvSure;

    @BindView(R.id.ll_pay_dialog)
    View mDialogView;

    List<RedPacketBean> redPcks;
    PayRedpacketAdapter adapter;
    LinearLayoutManager manager;

    //接口必须参数
    private String num;//Yes	string	追号期数
    private String bnum;//Yes	string	认购份数
    private String pnum;//Yes	string	保底份数
    private String type;//Yes	string	彩种英文名称
    private String desc = "自购";//Yes	string	合买宣传描述
    private String codes;//	Yes	string	投注号码
    private String gid;//Yes	string	彩种
    private String hbid;//Yes	string	红包ID
    private float hbmoney = 0;//	Yes	string	红包金额
    private String money;//	Yes	double	金额
    private String multiple;//	Yes	string	倍数
    private String multipleAll;//	Yes	string	倍数 追号里面所有倍数|分割
    private String name = "自购";//Yes	string	合买口号、标题
    private String password = "";//	Yes	string	密码//5d16b0a8cd0d08960e19026de910db16
    private String term;//Yes	string	期号
    private String wrate;//	Yes	string	总份数
    private String user = "";//Yes	string	用户名//cp2493200  test369
    private String votenums;//注
    private String pass;//过关方式
    private String lotteryType;//彩票类型 胜平负
    private String autocancel;//智能追号-中奖停止


    private String addtional;   //追加


    private String projectType; //1合买0自购
    private String oflag; //保密模式
//    private String wrate;  提成份额

    float actualMoney = 0;
    UserBean userBean;

    @Override
    public int getContentView() {
        return R.layout.activity_lottery_pay;
    }

    @Override
    protected int getStatusBarColor() {
        return R.color.b;
    }

    @Override
    protected void resetWindow() {
    }
    @BindView(R.id.ll_hb)
    View mLlRedPacket;

    @Override
    protected void initView() {
        super.initView();

        boolean isCanUseRedPacket = getIntent().getBooleanExtra(IS_CAN_USE_RED_PACKET, true);
        if(isCanUseRedPacket){
            mLlRedPacket.setVisibility(View.VISIBLE);
        }else{
            mLlRedPacket.setVisibility(View.GONE);
        }


        mDialogView.setVisibility(View.VISIBLE);
        showData();

      /*  showDialog();
         mDialogView.setVisibility(View.INVISIBLE);

        final HashMap<String, String> paramsMap = new HashMap<>();
        paramsMap.put("title",ChannelUtil.getChannel());
        paramsMap.put("channel","android");

        HttpManager.postAsyn(Constant_Url.CHECK_CHANNEL_CAN_USE, new HttpManager.StringCallback() {
            @Override
            public void onFailure(Request request, IOException e) {
                dissDialog();
                DisPlay("网络异常！！！");
                finish();
            }

            @Override
            public void onResponse(String response) {
                dissDialog();
                if (!TextUtils.isEmpty(response)) {
                    ProofBean proofBean = FastOk.get(response, ProofBean.class);
                    if("1".equals(proofBean.getStatus())){
                        //这里表示审核通过
                        mDialogView.setVisibility(View.VISIBLE);
                        showData();
                    }else{
                        //审核没有通过；
                        DisPlay("该彩种已停售！");
                        finish();
                    }
                }else{
                    finish();
                }
            }
        },paramsMap);*/

    }


    private void showData() {
        showDialog();
        checkLogin(new Callback() {

            @Override
            public void callbackField() {
                super.callbackField();
                dissDialog();
                finish();
            }

            @Override
            public void callbackSuccess() {
                super.callbackSuccess();

                if (userBean == null) {
                    userBean=PreferenceUtil.readUser(LotteryPayActivity.this);
                }

                dissDialog();
                //获取缓存的登录信息
                userBean = PreferenceUtil.readUser(LotteryPayActivity.this);
                redPcks = new ArrayList<>();
                num = getIntent().getStringExtra(PAY_NUM);//Yes	string	追号期数
                bnum = getIntent().getStringExtra(PAY_BNUM);//Yes	string	认购份数
                pnum = getIntent().getStringExtra(PAY_PNUM);//Yes	string	保底份数
                type = getIntent().getStringExtra(PAY_TYPE);//Yes	string	彩种英文名称
                desc = getIntent().getStringExtra(PAY_DESC);//Yes	string	合买宣传描述
                if (TextUtils.isEmpty(desc))
                    name = "自购";
                codes = getIntent().getStringExtra(PAY_CODES);//	Yes	string	投注号码
                gid = getIntent().getStringExtra(PAY_GID);//Yes	string	彩种
                hbid = getIntent().getStringExtra(PAY_HBID);//Yes	string	红包ID
                money = getIntent().getStringExtra(PAY_MONEY);//	Yes	double	金额
                multiple = getIntent().getStringExtra(PAY_MULTIPLE);//	Yes	string	倍数
                multipleAll = getIntent().getStringExtra(PAY_MULTIPLE_ALL);//	Yes	string	倍数,这里是有可能是盈利追号的和正常的倍数；这两个数据的格式是不一样的
                name = getIntent().getStringExtra(PAY_NAME);//Yes	string	合买口号、标题
                addtional = getIntent().getStringExtra(PAY_LOTTERY_ADDTIONAL);

                if (TextUtils.isEmpty(name))
                    name = "自购";
                term = getIntent().getStringExtra(PAY_TERM);//Yes	string	期号
                term = TextUtils.isEmpty(term) ? DateUtil.getCurrTime("yyyyMMdd") : term;//重新给个当天时间作为期号
                wrate = getIntent().getStringExtra(PAY_WRATE);//	Yes	string	总份数
                votenums = getIntent().getStringExtra(PAY_VOTENUMS);//	注
                pass = BaseUtils.strNoNull(getIntent().getStringExtra(PAY_PASS));//	过关方式

                lotteryType = BaseUtils.strNoNull(getIntent().getStringExtra(PAY_LOTTERY_TYPE));//彩票类型 胜平负
                actualMoney = Float.parseFloat(money);

                projectType = getIntent().getStringExtra(PAY_PROJECETYPE);//1合买 0自购
                oflag = getIntent().getStringExtra(PAY_OFLAG);//保密模式

                autocancel = getIntent().getStringExtra(PAY_AUTO_CANCEL);//智能追号

                user = PreferenceUtil.getUserName(LotteryPayActivity.this);
                password = PreferenceUtil.getPassword(LotteryPayActivity.this);
                if (type.equals("jczq")) {
                    gid = "41";
                } else {
                    gid = "55";
                }
                //设置布局管理器
                manager = new LinearLayoutManager(LotteryPayActivity.this);
                manager.setOrientation(LinearLayoutManager.HORIZONTAL);
                rv_pkg.setLayoutManager(manager);
                adapter = new PayRedpacketAdapter(LotteryPayActivity.this, redPcks, LotteryPayActivity.this);
                rv_pkg.setAdapter(adapter);
                updateText(hbmoney);
                getRedPacket(false);
            }
        });
    }

    //更新文案
    void updateText(float hbmoney) {
        tv_rmb.setText(Html.fromHtml(String.format(getString(R.string.lottery_money), "实际支付", actualMoney + "元")));
        tv_all_pay.setText(Html.fromHtml(String.format(getString(R.string.lottery_money), "本次共需支付", money + "元")));
        tv_hb_money.setText(Html.fromHtml(String.format(getString(R.string.lottery_money), "红包抵扣", hbmoney + "元")));
        tv_play.setText(lotteryType + " " + pass.replaceAll("[*]", "串"));
        tv_bs.setText(String.format(getString(R.string.lottery_bs), votenums, multiple));
        tvBalance.setText(Html.fromHtml(String.format(getString(R.string.lottery_money), "账户余额", userBean.getAllmoney() + "元")));
        if (!TextUtils.isEmpty(bnum)) {
            tv_rmb.setText(Html.fromHtml(String.format(getString(R.string.lottery_money), "实际支付", BaseUtils.getNumberSum(new String[]{bnum, pnum}) + "元")));
        }
    }

    /**
     * 是否直接展开红包
     *
     * @param openRed
     */
    void getRedPacket(final boolean openRed) {
        showDialog();
        Map<String, String> pair = new HashMap<>();
        pair.put(PAY_USER, user);//Yes	string	用户名
        pair.put(PAY_PASSWORD, password);//Yes	string	密码
//        pair.put(PAY_TYPE, type);//Yes	string	彩种英文名称
        pair.put(PAY_MONEY, money);//	Yes	double	金额
        HttpManager.postAsyn(Constant_Url.MY_REDPACKET, new HttpManager.StringCallback() {
            @Override
            public void onFailure(Request request, IOException e) {
                dissDialog();
                MyLog.i(request.toString());
            }

            @Override
            public void onResponse(String response) {
                dissDialog();
                RedpacketBody body = FastOk.get(response, RedpacketBody.class);
                if (body != null && body.getStatus() == 0) {
                    redPcks.clear();
                    redPcks.addAll(body.getRows());
                    adapter.notifyDataSetChanged();
                }
                if (openRed)
                    showHB();
            }
        }, pair);

    }

    @OnClick(R.id.ll_hb)
    void showHB() {
        showEmptyView();
        //未登录点击红包的时候需要提示登录 登录完成直接展示红包
        if (!isLogin()) {
            startActivityForResult(new Intent(this, LoginActivity.class), Constant_Result.SHOWREDPACKEG);
            return;
        }
        int animation = llhb.getVisibility() == View.GONE ? R.anim.rotate_0_180 : R.anim.rotate_180_360;
        startAnimation(iv_hb_icon, animation);
        llhb.startAnimation(new ExpandAnimation(llhb, 300, llhb.getVisibility() == View.GONE));
    }

    @OnClick(R.id.tv_sure)
    void sure(View v) {
        tvSure.setEnabled(false);
        checkIsLogin();
    }

    @OnClick(R.id.tv_cancel)
    void cancel() {
        onFinish();
    }

    private void checkIsLogin() {
        //登录且用户信息存在
        if (isLogin() && userBean != null) {
            loadUserInfo(new Callback() {
                @Override
                public void callbackSuccess() {
                    pay();
                }
            });
        } else {
            startActivityForResult(new Intent(this, LoginActivity.class), Constant_Result.LOTTERYPAY);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //这里我们要判断是否是从设置用户名那里设置用户名成功

        user = PreferenceUtil.getUserName(this);
        password = PreferenceUtil.getPassword(this);
        if (Constant_Result.LOTTERYPAY == requestCode && resultCode == RESULT_OK) {
            //这里是登陆的逻辑；
            loadUserInfo(new Callback() {
                @Override
                public void callbackSuccess() {
                    pay();
                }
            });
        } else if (Constant_Result.SHOWREDPACKEG == requestCode && resultCode == RESULT_OK) {
            //点击红包的时候，需要登陆的逻辑
            getRedPacket(true);
            loadUserInfo(null);
        } else if (Constant_Result.RECHARGE == requestCode && resultCode == RESULT_OK) {
            //这里表示从充值的那个界面完成；
            loadUserInfo(new Callback() {
                @Override
                public void callbackSuccess() {
                    pay();
                }
            });
           /* String msg = "您取消了本次充值";
            if (resultCode == RESULT_OK)
                msg = "由于银行汇款到账时间关系请稍后尝试下单购买";
            showAlertDialog("温馨提示", msg, "我知道了", "",
                    new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            finish();
                        }
                    },
                    null);*/
        }
    }

    //登录后需要加载用户信息
    protected void loadUserInfo(final Callback callback) {
        showDialog();
        HashMap<String, String> pair = new HashMap<>();
        pair.put("user", user);
        pair.put("password", password);
        HttpManager.postAsyn(Constant_Url.GET_USER_INFO, new HttpManager.StringCallback() {
            @Override
            public void onFailure(Request request, IOException e) {
                dissDialog();
                DisPlay(getString(R.string.error_network));
                if (tvSure != null)
                    tvSure.setEnabled(true);
            }

            @Override
            public void onResponse(String response) {
                dissDialog();
                userBean = FastOk.get(response, UserBean.class);
                if (userBean != null) {
                    if ("1011".equals(userBean.getStatus())) {//未登录返回首页 ios 逻辑
                        MyToast.showToast(LotteryPayActivity.this, userBean.getMessage());

                        userBean = null;
                        if (tvSure != null)
                            tvSure.setEnabled(true);
                    } else {
                        if (callback != null)
                            callback.callbackSuccess();
                    }
                    PreferenceUtil.writeUser(LotteryPayActivity.this, userBean);
                } else {
                    DisPlay(getString(R.string.error_network));
                    if (tvSure != null)
                        tvSure.setEnabled(true);
                }
            }
        }, pair);
    }

    //支付
    private void pay() {
        if (Lecai_SDK.from.equals("Follow")){
            //这里我们是需要加金额的；
            if (actualMoney > Float.parseFloat(userBean.getAllmoney())+hbmoney) {
                Float needRechargeMoney =actualMoney-Float.parseFloat(userBean.getAllmoney()) + hbmoney ;
                showReChargeDialog(needRechargeMoney.intValue()+"");
                return;
            }
            String allmoney = userBean.getAllmoney();
            float all = BaseUtils.convertToFloat(allmoney, 0);
            float money = all - actualMoney;
            userBean.setAllmoney(money+"");
            PreferenceUtil.writeUser(LotteryPayActivity.this, userBean);
            Intent intent = new Intent();
            intent.putExtra("hbid",hbid);
            intent.putExtra("hbmoney",hbmoney+"");
            setResult(RESULT_OK,intent);
            finish();
        }else{
            getTermInfo(new Callback() {
                @Override
                public void callbackSuccess() {
                    super.callbackSuccess();
                    float am = actualMoney;
                    //如果余额不足 提示跳转充值 回来继续支付
                    if (!TextUtils.isEmpty(bnum)) {
                        //发起合买的实际付款金额 = bnum + pnum
                        am = BaseUtils.getNumberSum(new String[]{bnum, pnum});
                    }
                    //这里我们是需要加金额的；
                    if (am > Float.parseFloat(userBean.getAllmoney())+hbmoney) {
                        Float needRechargeMoney =am-Float.parseFloat(userBean.getAllmoney()) + hbmoney ;
                        showReChargeDialog(needRechargeMoney.intValue()+"");
                    }
                    HashMap<String, String> pair = new HashMap<>();
                    pair.put(PAY_GID, gid);//Yes	string	彩种
                    pair.put(PAY_TERM, term);//Yes	string	期号
                    pair.put(PAY_LOTTERY_ADDTIONAL, addtional);//是否追加
                    pair.put("play", "1");
                    pair.put(PAY_CODES, codes);//	Yes	string	投注号码
                    pair.put(PAY_MULTIPLE, TextUtils.isEmpty(multipleAll) ? multiple : multipleAll);//	Yes	string	倍数
                    pair.put(PAY_TYPE, type);//Yes	string	彩种英文名称
                    pair.put(PAY_NAME, name);//Yes	string	合买口号、标题
                    pair.put(PAY_DESC, desc);//Yes	string	合买宣传描述
                    // pair.put(PAY_MONEY, String.valueOf(actualMoney));//	Yes	double	金额
                    pair.put(PAY_MONEY, String.valueOf(money));//	Yes	double	金额
                    pair.put("tnum", String.valueOf(actualMoney));
                    pair.put(PAY_PNUM, pnum);//Yes	string	保底份数
                    pair.put(PAY_BNUM, String.valueOf(actualMoney));//Yes	string	认购份数 api 文档
                    if (!TextUtils.isEmpty(bnum))
                        pair.put(PAY_BNUM, bnum);//Yes	string	认购份数 api 文档
                    pair.put(PAY_HBID, hbid);//Yes	string	红包ID
                    pair.put(PAY_HBMONEY, String.valueOf(hbmoney));//	Yes	string	红包金额
                    pair.put("imoneyrange", "");
                    pair.put("iminrange", "");

                    pair.put(PAY_WRATE, wrate);//	Yes	string	总份数
                    pair.put(PAY_OFLAG, oflag);//	Yes	string 保密模式
                    pair.put(PAY_PROJECETYPE, projectType);//	Yes	string	1合买0自购

                    pair.put(PAY_USER, userBean.getUsername());//Yes	string	用户名
                    pair.put(PAY_PASSWORD, password);//Yes	string	密码
                    pair.put(PAY_NUM, num);//Yes	string	追号期数

                    pair.put(SUN_ORDER_MODE,getIntent().getStringExtra(SUN_ORDER_MODE));
                    pair.put(SUN_ORDER_SLOGAN,getIntent().getStringExtra(SUN_ORDER_SLOGAN));
                    pair.put(IS_SHOW_ORDER,getIntent().getStringExtra(IS_SHOW_ORDER));

                    boolean payBalls = getIntent().getBooleanExtra(PAY_LOTTERY_BALLS, false);
                    if (!TextUtils.isEmpty(autocancel))
                        pair.put(PAY_AUTO_CANCEL, autocancel);//Yes	string	智能追号-中奖停止

                    String url;
                    if (type.startsWith("jcg")) {//竞彩冠军 冠亚军 jcgj jcgyj
                        url = Constant_Url.BET;
                    }else if (type.startsWith("jc") || type.equals("bjdc")) {
                        //竞彩类 北京单场 只有是混投调用balls 其余单关 混投奖金优化 其余奖金优化 其他栏目 调用ball
                        if (codes.startsWith("HH") && payBalls) {
                            url = Constant_Url.PLAY_URLs;
                        } else {
                            url = Constant_Url.PLAY_URL;
                        }
                    } else {
                        url = Constant_Url.BUY;
                    }
                    pair.put("channel","android");
                    pair.put("appstore", ChannelUtil.getChannel());
                    HttpManager.postAsyn(url, new HttpManager.StringCallback() {
                        @Override
                        public void onFailure(Request request, IOException e) {
                            MyLog.i(request.toString());
                            dissDialog();
                            MyToast.showToast(getBaseContext(), getString(R.string.faile_network));
                            if (tvSure != null)
                                tvSure.setEnabled(true);
                        }

                        @Override
                        public void onResponse(String response) {
                            if (tvSure != null)
                                tvSure.setEnabled(true);
                            dissDialog();
                            PlayItem playItem = FastOk.get(response, PlayItem.class);
                            if (playItem != null) {
                                MyToast.showToast(getBaseContext(), playItem.getMessage());
                                //投注成功，跳转到成功的页面
                                if ("0".equals(playItem.getStatus())) {
                                    if (!TextUtils.isEmpty(bnum)) {
                                        actualMoney = BaseUtils.getNumberSum(new String[]{bnum, pnum});
                                    }
                                    userBean.setAllmoney(String.valueOf(Float.parseFloat(userBean.getAllmoney()) - actualMoney));
                                    PreferenceUtil.writeUser(LotteryPayActivity.this, userBean);
                                    Intent intent = new Intent(LotteryPayActivity.this, SuccessActivity.class);
                                    intent.putExtra("tradeType", playItem.getTradeType());
                                    startActivity(intent);
                                    setResult(RESULT_OK);
                                    finish();
                                }else if( "1012".equals(playItem.getStatus()) ){
                                    //这里我们要跳转到绑定用户名和手机号；
                                    HashMap<String,String> map = new HashMap<>();
                                    map.put("user",PreferenceUtil.getUserName(LotteryPayActivity.this));
                                    map.put("password",PreferenceUtil.getPassword(LotteryPayActivity.this));
                                    //.putExtra("param", JSON.toJSONString(threeLoginPairmsMap)
                                    Intent intent = RegisterActivity.getIntent(LotteryPayActivity.this, false);
                                    intent.putExtra("param", JSON.toJSONString(map));
                                    //这里是需要nickname,password的
                                    startActivity(intent);
                                }
                            } else {
                                DisPlay(getString(R.string.error_network));
                            }
                        }
                    }, pair);
                }

                @Override
                public void callbackField() {
                    super.callbackField();
                    if (tvSure != null)
                        tvSure.setEnabled(true);
                    dissDialog();
                    DisPlay("获取期号失败");
                }
            });
        }


    }

    /**
     * 需要充值的金额
     * @param rechargeMoney
     */
    private void showReChargeDialog(final String rechargeMoney) {

        showAlertDialog("温馨提示", "您的账户余额不足，是否前往充值", "知道了", "前往",
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dissDialog();
                        if (tvSure != null)
                            tvSure.setEnabled(true);
                    }
                },
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dissDialog();
                        if (tvSure != null)
                            tvSure.setEnabled(true);
                        //这里
                        startActivityForResult(PayRechargeActivity.getIntent(LotteryPayActivity.this,rechargeMoney),Constant_Result.RECHARGE);
                    }
                });
        return;

    }



    void showEmptyView() {
        tv_no.setVisibility(redPcks.size() > 0 ? View.GONE : View.VISIBLE);
    }

    @OnClick(R.id.iv_left)
    void toLeft() {
        int firstItem = manager.findFirstVisibleItemPosition();
        if (redPcks.size() > 2 && firstItem > 0)
            rv_pkg.smoothScrollToPosition(firstItem - 1);
    }

    @OnClick(R.id.iv_right)
    void toRight() {
        int lastItem = manager.findLastVisibleItemPosition();
        if (redPcks.size() > 2 && lastItem < redPcks.size() - 1)
            rv_pkg.smoothScrollToPosition(lastItem + 1);
    }


    @Override
    public void onClickSetChangedText() {
        adapter.notifyDataSetChanged();
        hbmoney = 0;
        actualMoney = Float.parseFloat(money);
        hbid = null;
        if (adapter.getRedCheckIndex() > -1) {
            RedPacketBean redPacketBean = redPcks.get(adapter.getRedCheckIndex());
//            hbid = redPacketBean.getRedpacketid();
            //红包使用id
            hbid = redPacketBean.getId();
            hbmoney = ((redPacketBean.getRestmoney() > Float.valueOf(money)) ? Float.valueOf(money) : (redPacketBean.getRestmoney()));
            if (redPacketBean.getRestmoney() == 0)
                hbmoney = 0;
            actualMoney = Float.valueOf(money) - hbmoney;
        }
        updateText(hbmoney);
    }

    /**
     * 获取期号
     */
    void getTermInfo(final Callback callback) {
        showDialog();
        Map<String, String> map = new HashMap<>();
        map.put("type", type);
        HttpManager.postAsyn(Constant_Url.DLTTERM, new HttpManager.StringCallback() {
            @Override
            public void onFailure(Request request, IOException e) {
                MyLog.i(request.toString());
                if (callback != null)
                    callback.callbackField();
            }

            @Override
            public void onResponse(String response) {
                if (!TextUtils.isEmpty(response)) {
                    DltBody body = FastOk.get(response, DltBody.class);
                    if (body != null) {
                        if (TextUtils.isEmpty(multipleAll) && !TextUtils.isEmpty(body.getTermNo()))
                            term = body.getTermNo();
                        if (callback != null)
                            callback.callbackSuccess();
                    } else {
                        if (callback != null)
                            callback.callbackField();
                    }
                } else {
                    if (callback != null)
                        callback.callbackField();
                }
            }
        }, map);
    }





    private void showBuyInfo() {
//        Log.e(TAG, "code=" + formatCode());
//        Log.e(TAG, "totalMoney=" + totalMoney);
//        Log.e(TAG, "totalNum=" + totalNum);
//        Log.e(TAG, "multiple=" + multiple);
//        /**
//         * 此处提交之前先判断用户是否登录
//         */
//        Intent intent = new Intent(this, LotteryPayActivity.class);
//        intent.putExtra(PAY_VOTENUMS, String.valueOf(totalNum));
//        intent.putExtra(PAY_MULTIPLE, String.valueOf(multiple));
//        intent.putExtra(PAY_MONEY, String.valueOf(totalMoney));
//        String code = formatCode();
//        intent.putExtra(PAY_CODES, code.substring(0, code.length() - 1));   //这里的这个操作是去除，最后一个分号；
//        intent.putExtra(PAY_TYPE, type);
//        intent.putExtra(PAY_NAME, "自购");
//        intent.putExtra(PAY_NUM, String.valueOf(num));
//        if (cb_add_to.isChecked()) {
//            intent.putExtra(PAY_LOTTERY_ADDTIONAL, "1");
//        }
//        if (bean != null)
//            intent.putExtra(PAY_TERM, BaseUtils.strNoNull(bean.getTermNo()));
//        startActivityForResult(intent, Constant_Result.CLOSEPAGE);
//        Log.e("num", num + "_" + num);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Lecai_SDK.from = "recomment";
    }
}
